<template>
    <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="onLoad" :offset="10">
        <!-- @click="router.push(`/article-detail?articleId=${collect.article.id}`)" -->
        <van-card class="item" v-for="collect in list"
            :thumb="type === 1 ? collect.goods.picUrl : collect.article.picUrl" @click="
                type === 1
                    ? router.push({ name: 'goods', params: { id: collect.goods.id } })
                    : router.push({
                        path: '/article-detail',
                        query: { articleId: collect.article.id, a: 666 },
                    })
            ">
            <template #title>
                <p class="title">
                    {{ type=== 1 ? collect.goods.name : collect.article.title }}
                </p>
            </template>
            <template #price>
                <p class="desc">
                    {{ type=== 1 ? `￥${(collect.goods.price / 100).toFixed(2)}` : collect.article.desc }}
                </p>
            </template>
            <template #num>
                <p>{{ collect.created_at }}</p>
            </template>
        </van-card>
    </van-list>
</template>

<script setup>
import { useRouter } from "vue-router";
import usePageList from "@/views/Hooks/usePageList";
import { collecdList } from "@/api/collect";
import { defineProps } from "vue";

let props = defineProps({
    type: {
        type: Number,
    },
});

let router = useRouter();

let { loading, finished, onLoad, list } = usePageList(collecdList, {
    page: 1,
    limit: 10,
    type: props.type,  //接口需要type 判断是文章还是商品
});
</script>